import request from '@/utils/request'
import { successMsg } from '@/utils/comm'

export const IMAGE_API = 'http://1.117.95.71:3909'

// restful 风格的 简单增删改查 api
export function getComm(url, id) {
  return request({
    url: `/${url}/${id}`,
    method: 'get'
  })
}

export function getListComm(url, params) {
  return request({
    url: `/${url}/list`,
    method: 'get',
    params
  })
}
export function getMyListComm(url, params) {
  return request({
    url: `/${url}/e/my`,
    method: 'get',
    params
  })
}

export function getPageComm(url, params) {
  return request({
    url: `/${url}/page`,
    method: 'get',
    params
  })
}

export function addComm(url, data) {
  return request({
    url: `/${url}`,
    method: 'post',
    data
  })
}
export function addMsgComm(url, data) {
  return request({
    url: `/${url}`,
    method: 'post',
    data
  }).then(() => { successMsg() })
}

export function updateComm(url, data) {
  return request({
    url: `/${url}`,
    method: 'put',
    data
  })
}
export function updateMsgComm(url, data) {
  return request({
    url: `/${url}`,
    method: 'put',
    data
  }).then(() => { successMsg() })
}

export function delComm(url, id) {
  return request({
    url: `/${url}/${id}`,
    method: 'delete'
  })
}
export function delMsgComm(url, id) {
  return request({
    url: `/${url}/${id}`,
    method: 'delete'
  }).then(() => { successMsg() })
}

export function urlGetComm(url, params) {
  return request({
    url: url,
    method: 'get',
    params
  })
}

export function urlPostComm(url, data) {
  return request({
    url: url,
    method: 'post',
    data
  })
}

